﻿using System;
using System.Drawing;
using G.Model;

namespace GameControls
{
    public abstract class BoardShapeDisplayer : IDisposable
    {
        private readonly BoardShapeContainer _ShapeContainer;
        private readonly GameDisplayer _GameDisplayer;
        private readonly BoardShape _Shape;
        private readonly GameLocation _Location;

        public BoardShapeDisplayer(GameDisplayer displayer, 
                                   Point point,
                                   BoardShape shape, 
                                   BoardShapeContainer shapeContainer)
        {
            _GameDisplayer = displayer;
            _ShapeContainer = shapeContainer;
            _Location = shapeContainer.ToGameLocation(point);
            _Shape = shape;
            _Shape.Location = point;
            _Shape.Size = new System.Drawing.Size(
                shapeContainer.SquareSize, shapeContainer.SquareSize);
            _GameDisplayer.Displayers.Add(this);
            _ShapeContainer.Add(shape);
        }
        
        public virtual void Dispose()
        {
            _ShapeContainer.Remove(_Shape);
        }
        
        public BoardShape Shape
        {
            get { return _Shape; }
        }

        public BoardShapeContainer ShapeContainer
        {
            get { return _ShapeContainer; }
        }
        
        public GameLocation Location
        {
            get { return _Location; }
        }

        public GameDisplayer GameDisplayer
        {
            get { return _GameDisplayer; }
        }

        public void Clear()
        {
            _GameDisplayer.ClearShape(_Location);
        }

        public abstract void DisplayIcon();

    }
}
